#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int max = 0;
        for (const auto& tmp : nums)
            max = (max >= 0 ? max + tmp : tmp);
        return max;
    }
};
int main()
{
    vector<int> nums;
    int num = 0;
    while (cin >> num)
    {
        if (num == 0)
            break;
        nums.push_back(num);
    }
    int ret = Solution().maxSubArray(nums);
    cout << ret << endl;
    return 0;
}